import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDDropSet {
	/**编号(主键)*/
	id,
	/**掉落组id*/
	DropSetid,
	/**概率下限--符号<=*/
	rateLow,
	/**概率上限(万分比)--符号<=*/
	rateUp,
	/**物品类型--1.资源点2.道具3.装备4.符文5.魔纹6.宠物*/
	itemType,
	/**道具id*/
	itemid,

	/**枚举数量*/
	EnumCount
}



export class CDDropSet{
	/**编号(主键)*/
	public id: number;
	/**掉落组id*/
	public DropSetid: number;
	/**概率下限--符号<=*/
	public rateLow: number;
	/**概率上限(万分比)--符号<=*/
	public rateUp: number;
	/**物品类型--1.资源点2.道具3.装备4.符文5.魔纹6.宠物*/
	public itemType: number;
	/**道具id*/
	public itemid: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDDropSet.id: return this.id;
			case E_CDDropSet.DropSetid: return this.DropSetid;
			case E_CDDropSet.rateLow: return this.rateLow;
			case E_CDDropSet.rateUp: return this.rateUp;
			case E_CDDropSet.itemType: return this.itemType;
			case E_CDDropSet.itemid: return this.itemid;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDDropSet.id: this.id = v; break;
			case E_CDDropSet.DropSetid: this.DropSetid = v; break;
			case E_CDDropSet.rateLow: this.rateLow = v; break;
			case E_CDDropSet.rateUp: this.rateUp = v; break;
			case E_CDDropSet.itemType: this.itemType = v; break;
			case E_CDDropSet.itemid: this.itemid = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDDropSet> = new HashMap<number, CDDropSet>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDDropSet[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDDropSet();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].DropSetid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rateLow = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rateUp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemid = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDDropSet{
		return this.datas ? this.datas.get(id) : null;
	}
}
